<?php
include("include/config.inc.php");
if(!isset($_SESSION['s_activId']))
{
  header("location:checklogin.php");
}

$deleteLoading = "DELETE FROM loadinginvoicedetail 
                   WHERE  loadingInvoiceDetailId = ".$_REQUEST['loadingInvoiceDetailId'];
$deleteLoadingRes = mysql_query($deleteLoading);
if(!$deleteLoadingRes)
{
	echo("DELETE FAIL");
}
else
{
  $loadinginvoicedetail = "DELETE FROM loadinginvoicedetail 
                          WHERE loadingInvoiceDetailId = ".$_REQUEST['loadingInvoiceDetailId'];
  $loadinginvoicedetailRes= mysql_query($loadinginvoicedetail);
  
  $selMoreDetailRecord = "SELECT loadingInvoiceDetailId FROM loadinginvoicedetail WHERE loadingInvoiceId = ".$_REQUEST['loadingInvoiceId'];
  $selMoreDetailRecordRes = mysql_query($selMoreDetailRecord);
  $resultRes = mysql_num_rows($selMoreDetailRecordRes);
  if($resultRes == 0)
  {
    $deleteLoadingInvoice = "DELETE FROM loadinginvoice 
                           WHERE loadingInvoiceId = ".$_REQUEST['loadingInvoiceId'];
    $deleteLoadingInvoiceRes = mysql_query($deleteLoadingInvoice);                        
  }

  header("Location:loadinginvoice.php?loadingInvoiceId=".$_REQUEST['loadingInvoiceId']);
}
?>